<script setup lang="ts">
import {ref} from 'vue'
import {renewalAll,renSave} from '@/api/platform/enterprise'
import {ElMessage} from "element-plus";

const ruleForm = ref({
  eid:0,
  money: "",
  month: ""
})
const expireDate = ref('')
const moneys = ref('')
//声明事件
const emits = defineEmits(["close", "refresh"])
const props = defineProps({
  "visible": {
    type: Boolean,
    default: false
  }
})

async function queryById(id) {
  ruleForm.value.eid=id
  let data = {
    id: id
  };

  let res = await renewalAll(data)
  if (res.code == 200) {
    expireDate.value = res.data.expireDate
    moneys.value = res.data.money
  }
}
async function save(){
let res = await renSave(ruleForm.value)
if (res.code==200){
  ElMessage({
    message: '保存成功',
    type: 'success'
  })
  //关闭窗口
  cls();
  //通知父窗口刷新数据
  emits("refresh");
}
}
//暴露
defineExpose({queryById})

//关闭窗口
function cls() {
  //抛出自定义事件
  emits("close");
}
</script>

<template>
  <el-dialog :model-value="visible" :close-on-click-modal="false" title="企业续费" width="532" @close="cls">
    <div>
      <span style="margin-left: 50px;line-height: 4">当前到期日期:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ expireDate }}</span>
      <el-form style="max-width: 600px" :model="ruleForm" label-width="150px" status-icon>
        <el-form-item label="增加续费时间:">
          <el-input v-model="ruleForm.month"/>
        </el-form-item>
        <el-form-item label="续费金额:">
          <el-input v-model="ruleForm.money"/>
        </el-form-item>
        <el-form-item label="当前企业可用余额:">
          <el-input v-model="moneys" disabled/>
        </el-form-item>
        <el-button type="primary" @click="save">保存</el-button>
        <el-button @click="cls">不保存关闭</el-button>
      </el-form>
    </div>
  </el-dialog>
</template>
<style scoped lang="scss">

</style>
